package com.type.web;

import java.io.PrintWriter;
import java.util.ArrayList;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.type.service.DateTaskService;
import com.type.vo.DateTaskVO;
import com.vo.UserVO;

@Controller
public class TypeElevenController {
	
	@Resource(name="DateTaskService")
	private DateTaskService service;
	
	@RequestMapping("/JsonTaskDay.do")
	public void selectDayTask(@RequestParam(value="date")String date,HttpServletResponse response,HttpSession session){
		response.setContentType("text/html;charset=utf-8");		//한글 인코딩
		
		ArrayList<DateTaskVO> list = null;
		UserVO user= new UserVO();
		
		if(session.getAttribute("user")==null){		//로그인 하지 않았다면 임의의 값
			user.setId("user01");
		} else{
			user = (UserVO) session.getAttribute("user");		//로그인 했다면
		}
		try {
			list = service.selectTaskByIDNDate(user.getId(), date);	
			JSONArray json = new JSONArray();
			for(int i=0; i<list.size(); i++){
				DateTaskVO taskVO = list.get(i);
				json.add(taskVO);				//json 객체에 담아 준다.
			}
			PrintWriter out = response.getWriter();		//응답쪽에 보내주기위한 PrintWriter클래스 생성
			out.println(json);							//정보가 담긴 json 객체를 보낸다.
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}
		
	}
	
}
